#include <bits/stdc++.h>
using namespace std;

inline int read() {
	int x = 0, f = 0; char ch = getchar();
	while (ch < '0' or ch > '9') f |= (ch == '-'), ch = getchar();
	while (ch >= '0' and ch <= '9') x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

int __stk[128], __top;
inline void write(int x) {
    if(x < 0) putchar('-'), x = -x;
	do { __stk[++__top] = x % 10, x /= 10; } while (x);
	while (__top) putchar(__stk[__top--] + '0');
}

const int mod = 998244353;

void Min(int &x, int y) { y < x and (x = y); }
void Max(int &x, int y) { y > x and (x = y); }

void inc(int &x, int y) { (x += y) >= mod and (x -= mod); }
void mul(int &x, int y) { x = 1ll * x * y % mod; }

int q_pow(int x, int k) { int res = 1; for (; k; k >>= 1, mul(x, x)) if (k & 1) mul(res, x); return res; }

bool stmer;

const int N = 2e6 + 10;

int n;
int p[N], rk[N], d[N], fa[N], val[N];

struct node {
    int l, r;
} f[N];

int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }

void merge(int x, int y) {
    x = find(x), y = find(y); 
    if (x ^ y) {
        Min(f[x].l, f[y].l), Max(f[x].r, f[y].r);
        fa[y] = x;
    }
}

vector<int> e[N], q;

void solve() {
    for (int i = 0; i < n; i++) e[i].clear(); q.clear();

    n = read();
    for (int i = 0; i < n; i++) p[i] = read(), rk[p[i]] = i;
    for (int i = 0; i < 2 * n - 1; i++) d[i] = read();

    for (int i = 0; i < n; i++) fa[i] = i, f[i] = { rk[i], rk[i] };

    int mid = 0, r = -1;
    for (int i = 0; i < n; i++) {
        if (!(d[i << 1] & 1)) return puts("-1"), void();

        int st = 0, p = i << 1;
        if (p < r) st = min(r - p, d[2 * mid - p] / 2);
        for (int j = st; j << 1 < d[p]; j++) {
            if (i - j < 0 or i + j >= n) return puts("-1"), void();
            merge(i - j, i + j);
        }
        if (p + d[p] > r) mid = p, r = p + d[p];

        if (i == n - 1) continue;
        if (d[i << 1 | 1] & 1) return puts("-1"), void();
        
        st = 0, p = i << 1 | 1;
        if (p < r) st = min(r - p, d[2 * mid - p]);
        for (int j = st; j << 1 < d[p]; j++) {
            if (i - j < 0 or i + j + 1 >= n) return puts("-1"), void();
            merge(i - j, i + j + 1);
        }
        if (p + d[p] > r) mid = p, r = p + d[p];
    }

    int id = 0;
    for (int i = 0; i < n; i++) {
        if (i <= f[find(p[id])].r) merge(p[id], p[i]);
        else id = i;
    }

    for (int i = 0; i + 1 < n; i++) {
        int x = p[i] + 1, y = p[i + 1] + 1;
        bool flag = 1;
        while (max(x, y) < n) {
            if (rk[x] > rk[y]) break;
            else { flag = 0; break; }
            x++, y++;
        }
        x--, y--;
        if (x != (n - 1) and flag) {
            x = find(x), y = find(y);
            e[x].push_back(y), e[y].push_back(x);
        }
    }

    id = 0, q.push_back(p[0]);
    for (int i = 0; i < n; i++) {
        if (i <= f[find(p[id])].r) merge(p[id], p[i]);
        else id = i, q.push_back(p[id]);
    }

    for (int i = 0; i < n; i++) {
        int x = i - d[i << 1] / 2 - 1, y = i + d[i << 1] / 2 + 1;
        if (x >= 0 and y < n) {
            x = find(x), y = find(y);
            if (x == y) return puts("-1"), void();
            e[x].push_back(y), e[y].push_back(x);
        }
        if (i + 1 < n) {
            x = i - d[i << 1 | 1] / 2, y = i + d[i << 1 | 1] / 2 + 1;
            if (x >= 0 and y < n) {
                x = find(x), y = find(y);
                if (x == y) return puts("-1"), void();
                e[x].push_back(y), e[y].push_back(x);
            }
        }
    }

    q[0] = find(q[0]), val[q[0]] = 0;
    for (int i = 1; i < q.size(); i++) {
        q[i] = find(q[i]); bool flag = 0;
        for (int v : e[q[i]]) if (find(v) == q[i - 1]) flag = 1;
        if (flag) val[q[i]] = val[q[i - 1]] + 1;
        else {
            val[q[i]] = val[q[i - 1]], merge(q[i], q[i - 1]);
        }
        if (val[q[i]] > 25) return puts("-1"), void();
    }
    
    for (int i = 0; i < n; i++) putchar('a' + val[find(i)]);
    putchar('\n');
    // for (int i = 0; i < n; i++) cout << find(i) << ' ';
    // cout << '\n';
}

bool edmer;
signed main() {
	freopen("string.in", "r", stdin);
	freopen("string.out", "w", stdout);
	cerr << "[Memory] " << (&stmer - &edmer) / 1024 / 1024 << " MB\n";
	
    int T = read();
    while (T--) solve();

    cerr << "[Runtime] " << (double) clock() / CLOCKS_PER_SEC << " seconds\n";
	return 0;
} 